<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="Connect.*" %>

<%
	// Redirect to the home page if the user is not a manager or employee.
	if (session.getAttribute("user_type") == null) {
		response.sendRedirect("no_permission.jsp");
	} else if (!session.getAttribute("user_type").equals("0") && !session.getAttribute("user_type").equals("1")) {
		response.sendRedirect("no_permission.jsp");
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//Dth HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dth">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<title>Hammer Time Auctions</title>
</head>
<body>
	<div id="content">
		<%@include file="header.jsp"%>
		<h1>Customer Mailing List</h1>
		<hr></hr>
		<%
			// Getting information and updating the database.
			java.sql.Connection conn = null;
			try {
				// Connect to the database.
				Class.forName(ConnectionInfo.myJDBCDriver()).newInstance();
				java.util.Properties sysprops = System.getProperties();
				sysprops.put("user", ConnectionInfo.myUserID());
				sysprops.put("password", ConnectionInfo.myPassword());
				conn = java.sql.DriverManager.getConnection(ConnectionInfo.myURL(), sysprops);

				// Check if the requested username and password combination exists.
				java.sql.Statement statement = conn.createStatement();
				java.sql.ResultSet rs = statement
						.executeQuery("SELECT users.username, email FROM users RIGHT JOIN customers ON users.username = customers.username ORDER BY username");
				out.println("<table class=\"center data-table\"><tr><th>Username</th><th>Email</th></tr>");
				while (rs.next()) {
					out.println("<tr><td>" + rs.getString("username") + "</td><td>" + rs.getString("email") + "</td></tr>");
				}
				out.println("</table>");
			} catch (Exception e) {
				e.printStackTrace();
				out.print(e.toString());
			} finally {
				try {
					conn.close();
				} catch (Exception ee) {
				}
			}
		%>
	</div>
	<hr></hr>
	<%@include file="footer.jsp"%>
</body>
</html>